﻿using A.M.ETO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Q.M.Sell.Application.IServices;
using Q.M.Sell.Doamin.Entity;
using Q.M.Sell.Infrastruecure.IRepository;
using Q.M.Sell.Infrastruecure.Repository;
using System.Linq.Expressions;

namespace Q.M.Sell.Write.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Sales_productWriteController : ControllerBase
    {
        private readonly ISales_productServices sales_ProductServices;
        public Sales_productWriteController(ISales_productServices sales_ProductServices)
        {
            this.sales_ProductServices = sales_ProductServices;
        }
        /// <summary>
        ///订单下的产品
        /// </summary>
        /// <param name="sales_number"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Getproduct(string? sales_number, int pageIndex, int pageSize)
        {
            PageETO<sales_product> pageETO = new PageETO<sales_product>();
            Expression<Func<sales_product, bool>> wherexp = i => true;
            if (sales_number != null)
            {
                wherexp = i => i.sales_number == sales_number;
            }
            var list = await sales_ProductServices.GetShowInforAsync(pageSize, pageIndex, wherexp);
            pageETO.TotalCount = list.TotalCount;
            pageETO.PageCount = list.PageCount;
            pageETO.Data = list.Data;
            return Ok(pageETO);
        }
        /// <summary>
        /// 反填销售订单下的产品
        /// </summary>
        /// <param name="salesid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> FindproductInfo(string? salesid)
        {
            var res = await sales_ProductServices.FindproductInfo(salesid);
            return Ok(res);

        }
    }
}
